use anyhow::Result;
use simple_logger::SimpleLogger;

#[tokio::main]
async fn main() {
    // init the logger
    SimpleLogger::new()
        .with_colors(true)
        .with_level(log::LevelFilter::Debug)
        // set Error log level for 3th crates
        .with_module_level("reqwest", log::LevelFilter::Error)
        .with_module_level("selectors", log::LevelFilter::Error)
        .with_module_level("html5ever", log::LevelFilter::Error)
        .init()
        .unwrap();

    match major().await {
        Ok(_) => {}
        Err(e) => {
            // print the error message
            // and exit with code 101
            log::error!("Error: {}", e);
            std::process::exit(101);
        }
    }
}

async fn major() -> Result<()> {
    use libs::get_version::DstVersionStore;

    let mut store = DstVersionStore::new();
    store.update().await?;
    for ii in store.iter() {
        log::debug!("{}", ii);
    }
    for i in store.newest_version() {
        let Some(v) = i else {
            continue;
        };
        log::debug!("newest version: {}", v);
    }
    Ok(())
}
